package org.cytoscape.myapp.cytoscape_app_v1.internal.metrics.domain;

import java.util.HashMap;

public class UserPositionMapping {
	
	protected HashMap<Integer, String> userIdByPosition;
	protected HashMap<String, Integer> positionByUserId;
	protected HashMap<String, User> users;
	
	public UserPositionMapping(HashMap<String, User> users) {
		this.users=users;
		this.positionByUserId=new HashMap<String, Integer>();
		this.userIdByPosition=new HashMap<Integer, String>();
		mappingPositions();
	}
	
	private void mappingPositions() {
		Integer pos=0;
		for (String userId : users.keySet()) {
			userIdByPosition.put(pos, userId);
			positionByUserId.put(userId, pos);
			pos++;
		}
	}
	
	/**
	 * Return the user ID given a Matrix position (index)
	 * @param position
	 * @return
	 */
	public String getUserIdByPosition(int position){
		return userIdByPosition.get(position);
	}

	/**
	 * Return a Matrix position (index) given a user ID
	 * @param userId
	 * @return
	 */
	public int getPositionByUserId(String userId) {
		return positionByUserId.get(userId);
	}

	public HashMap<String, User> getUsers() {
		return this.users;
	}
}
